# coding=utf-8

def nand(x, y, w1 = -2, w2 = -2, b = 3):
    assert x in [0, 1]
    assert y in [0, 1]

    r = w1 * x + w2 * y + b

    return 1 if r > 0 else 0


def test():
    assert nand(0, 0) == 1
    assert nand(0, 1) == 1
    assert nand(1, 0) == 1
    assert nand(1, 1) == 0


def perceptron(x1, x2):
    p1 = nand(x1, x2)
    print(F"p1(x1 = {x1}, x2 = {x2}) = {p1}")
    p2 = nand(x1, p1)
    print(F"p2(p1 = {p1}, x2 = {x2}) = {p2}")
    p3 = nand(p1, x2)
    print(F"p3(p1 = {p1}, x2 = {x2}) = {p3}")
    p4 = nand(p1, p1)
    print(F"x1*x2: p4(p1 = {p1}, p1 = {p1}) = {p4}")
    p5 = nand(p2, p3)
    print(F"x1+x2: p5(p2 = {p2}, p3 = {p3}) = {p5}")


def main():
    for x1 in [0, 1]:
        for x2 in [0, 1]:
            print("-" * 16)
            print("x1 = ", x1)
            print("x2 = ", x2)
            perceptron(x1, x2)


if __name__ == '__main__':
    test()
    main()
